<?php

namespace App\Models;

use App\Services\AlipayService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class InsureRate extends Model
{
    use HasFactory;
    protected $table = 'sp_insure_rate_2';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //获取保险费率
    protected function getInsureRate($goods_id,$rent_month){
        $insurance_category = Goods::from('sp_goods_2 as g')->leftjoin('sp_category as c','g.category_id','c.id')->where('g.id',$goods_id)->value('insurance_category');
        if(!empty($insurance_category)){
            $insure_rate = InsureRate::where([['type',$insurance_category],['beginMonth','<',$rent_month],['endMonth','>=',$rent_month]])->value('rate');
        }
        $insure_rate = !empty($insure_rate)?$insure_rate:0;
        return $insure_rate;
    }

}
